<script>
	// #ifdef APP-PLUS
	import {
		devicesStore
	} from "@/store/devices.js"
	// 检测升级APP
	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update.js'
	import tool from "@/util/tool.js"
	// #endif
	export default {
		onLaunch: async function() {
			// if(process.env.NODE_ENV === 'development'){
			// 	uni.removeStorageSync('setting')
			// 	uni.removeStorageSync('PeripheralConfig')
			// 	console.log('App Launch', uni.getSystemInfoSync().deviceId)
			// }
			
			// #ifdef APP-PLUS
			// 检查APP更新
			checkUpdate().then((res) => {
				uni.showToast({
					title: res.result.message,
					icon: 'none'
				})
			})

			let devices = devicesStore()
			let setting = uni.getStorageSync('setting')
			
			devices.$patch((state) => {
				if (setting) {
					for (let i in state.setting) {
						for (let j in state.setting[i]) {
							Object.keys(setting[i]).forEach((keyName) => {
								if (j == keyName) {
									state.setting[i][j] = setting[i][j]
								}
							})
						}
					}
				}
			})
			
			// 批量删除缓存目录（需自行获取路径）
			tool.deleteFile("/storage/emulated/0/Android/data/uni.UNI3F59049/apps/__UNI__3F59049/doc/snapshot"); //前置摄像头截图临时图片
			tool.deleteFile("/storage/emulated/0/Android/data/uni.UNI3F59049/doc/snapshot/"); //网络摄像头截图临时图片
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		onError: function(err) {
			console.log('uni-app报错时触发：', err)
			uni.showModal({
				content: err
			})
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-plus/index.scss";
	@import "@/static/common.scss";
</style>